<template>
    <div class="ExportButtonWrap">
        <a-button @click="handClick" :loading="loading">{{ menuId == '977' ? '台账导出' : '导出' }}</a-button>
    </div>
</template>
<script>
import qs from "qs";
export default {
    name: 'ExportButton',
    props: {
        aParams: {
            type: Object,
        },
        menuId: {
            type: [String, Number],
        }
    },
    data() {
        return {
            loading: false,
        }
    },
    methods: {
        handClick() {
            this.getQuest();
        },
        getQuest() {
            let tempUrl;
            if (this.menuId == '994') {
                tempUrl = this.$exportMHQ;
            } else if (this.menuId == '995') {
                tempUrl = this.$exportQG;
            } else if (this.menuId == 977) {
                tempUrl = this.$mhqtzExport;
            }
            if (!tempUrl) {
                return;
            }
            let params = {
                ...this.aParams,
            }
            const timestamp = new Date().getTime();
            this.$notification.open({
                key: timestamp,
                duration: null,
                message: "提示",
                icon: '',
                description: (
                    <div>
                        <span>导出中，请稍后</span>
                    </div>
                ),
                onClick: () => { },
            });
            this.loading = true;
            let str = qs.stringify(params);
            let link = document.createElement("a");
            link.style.display = "none";
            // 兼容不同浏览器的URL对象
            const url = window.URL || window.webkitURL || window.moxURL;
            link.href = `${tempUrl}?${str}`;
            link.setAttribute("download", `导出测试.xlsx`);
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            url.revokeObjectURL(link.href);
            setTimeout(() => {
                this.$notification.close(timestamp)
                this.loading = false;
            }, 1500)
        }
    }
}
</script>
<style lang="less" scoped>
.ExportButtonWrap {}
</style>